'use strict';

/*
 * 路由配置
 * 
 * @author yangw
 * @since 1.0.0
 */
app.run(function ($rootScope,   $state,   $stateParams) {
    	  /*设置路由传参对象到根Scope中*/
          $rootScope.$state = $state;
          $rootScope.$stateParams = $stateParams;        
  })
  .config(function ($stateProvider, $urlRouterProvider) {

          $urlRouterProvider.otherwise('/app/home');//缺省跳转状态         
          $stateProvider
          .state('app', {
              abstract: true,  //抽象状态不会直接被激活，但可为子状态提供继承
              url: '/app',
              templateUrl: encodeURL('/direct/app') //定义整个框架布局,使用的direct前缀，会自动寻找views/app.jsp页面
          })
          .state('layout', {
              abstract: true,
              url: '/layout',
              templateUrl: encodeURL('/resources/views/blocks/layout.html')
          })
          .state('lockscreen', {
              url: '/lockscreen',
              templateUrl: encodeURL('/resources/views/home/lockscreen.html')
          })
          .state('app.home', {
              url: '/home',
              templateUrl: encodeURL('/resources/views/home/homepage.html'),
              resolve: {
                  deps: function( $ocLazyLoad ){
                      return $ocLazyLoad.load(encodeURL('/resources/js/controller/chart/chartcontroller.js'));
                  }
              }
          })
          .state('app.profile', {
              url: '/profile',
              templateUrl: encodeURL('/resources/views/home/profile.html')
          })
          
          /****************************** JSP MODE ******************************/
          .state('app.jsp', {
              url: '/jsp',
              template: '<div ui-view class="fd-enter"></div>'
          })
          .state('app.jsp.pagequery', {
              url: '/pagequery/:pageNum',
              templateUrl: function ($stateParams){
            	  return encodeURL('/jspmode/pagequery?pageNum='+$stateParams.pageNum);
              }
          })
          .state('app.jsp.beancrud', {
              url: '/beancrud',
              templateUrl: encodeURL('/jspmode/beanlist')
          })
          
          /****************************** Standard MODE ******************************/
          .state('app.standard', {
              url: '/standard',
              template: '<div ui-view class="fd-enter"></div>'
          })
          .state('app.standard.restfull', {
              url: '/restfull',
              templateUrl: encodeURL('/resources/views/standard/beanlist.html'),
              resolve: {
                  deps: function( $ocLazyLoad ){
                      return $ocLazyLoad.load([encodeURL('/resources/js/services/standard/beanlistservice.js'),
                                               encodeURL('/resources/js/controller/standard/beanlistcontroller.js')]);
                  }
              }
          })
          .state('app.standard.logpush', {
              url: '/logpush',
              templateUrl: encodeURL('/resources/views/standard/logpush.html'),
              resolve: {
                  deps: function( uiLoad ){
                	  return uiLoad.load(encodeURL('/resources/js/controller/standard/logpushcontroller.js'));
                  }
              }
          })
          .state('layout.contact', {
              url: '/contact',
              templateUrl: encodeURL('/resources/views/standard/contact.html'),
              resolve: {
                  deps: function( $ocLazyLoad ){
                      return $ocLazyLoad.load(encodeURL('/resources/js/controller/standard/contactcontroller.js'));
                  }
              }
           })
          
          /****************************** Back Component ******************************/
          .state('app.backcomponent', {
              url: '/backcomponent',
              template: '<div ui-view class="fd-enter"></div>'
          })
          .state('app.backcomponent.sqlmapper', {
              url: '/sqlmapper',
              templateUrl: encodeURL('/resources/views/backcomponent/sqlmapper.html'),
              resolve: {
                  deps: function( $ocLazyLoad ){
                      return $ocLazyLoad.load('ngGrid').then(
                          function(){
                          	 return $ocLazyLoad.load(encodeURL('/resources/js/controller/backcomponent/sqlcontroller.js'));
                          }
                      ); 
                  }
              }
          })
          .state('app.backcomponent.soap', {
              url: '/soap',
              templateUrl: encodeURL('/resources/views/backcomponent/soap.html'),
              resolve: {
                  deps: function( $ocLazyLoad ){
                      return $ocLazyLoad.load({name:'angular-skycons', files:[encodeURL('/resources/js/compont/skycons.js'),
                               encodeURL('/resources/vendor/libs/moment.min.js'),
                               encodeURL('/resources/js/compont/angular-skycons.js'),
                               encodeURL('/resources/js/controller/backcomponent/soapcontroller.js')
                      ]});
                  }
              }
          })
          
          /****************************** UI 模块开始 ******************************/
          .state('app.ui', {
              url: '/ui',
              template: '<div ui-view class="fd-enter"></div>'
          })
          .state('app.ui.css', {
              url: '/css',
              templateUrl: encodeURL('/resources/views/uikits/cssbase.html')
          })          
          .state('app.ui.fonts', {
              url: '/fonts',
              templateUrl: encodeURL('/resources/views/uikits/fonts.html')
          })
          .state('app.ui.buttons', {
              url: '/buttons',
              templateUrl: encodeURL('/resources/views/uikits/buttons.html')
          })
          .state('app.ui.grids', {
              url: '/grids',
              templateUrl: encodeURL('/resources/views/uikits/grids.html')
          })
          .state('app.ui.widgets', {
              url: '/widgets',
              templateUrl: encodeURL('/resources/views/uikits/widgets.html')
          })  
          .state('app.ui.sortable', {
              url: '/sortable',
              templateUrl: encodeURL('/resources/views/uikits/sortable.html')
          })
          .state('app.ui.portlet', {
              url: '/portlet',
              templateUrl: encodeURL('/resources/views/uikits/portlet.html')
          })
          .state('app.ui.timeline', {
              url: '/timeline',
              templateUrl: encodeURL('/resources/views/uikits/timeline.html')
          })
          .state('app.ui.dialog', {
              url: '/dialog',
              templateUrl: encodeURL('/resources/views/uikits/dialog.html'),
              resolve: {
                  deps: function( $ocLazyLoad ){
                      return $ocLazyLoad.load(encodeURL('/resources/js/controller/uikits/dialogcontroller.js'));
                  }
              }
          })
          .state('app.ui.toaster', {
              url: '/toaster',
              templateUrl: encodeURL('/resources/views/uikits/toaster.html'),
              resolve: {
                  deps: function( $ocLazyLoad ){
                	  return $ocLazyLoad.load(encodeURL('/resources/js/controller/uikits/toastercontroller.js'));                    
                  }
              }
          })
          .state('app.ui.bootstrap', {
              url: '/bootstrap',
              templateUrl: encodeURL('/resources/views/uikits/bootstrap.html'),
              resolve: {
                  deps: function( $ocLazyLoad ){
                      return $ocLazyLoad.load(encodeURL('/resources/js/controller/uikits/bootstrapcontroller.js'));
                  }
              }
          })
          
          /****************************** TABLE 模块开始 ******************************/
          .state('app.table', {
              url: '/table',
              template: '<div ui-view class="fd-enter"></div>'
          })
          .state('app.table.tablestatic', {
              url: '/tablestatic',
              templateUrl: encodeURL('/resources/views/table/tablestatic.html')
          }) 
          .state('app.table.datatable', {
              url: '/datatable',
              templateUrl: encodeURL('/resources/views/table/datatable.html')
          }) 
          .state('app.table.footable', {
              url: '/footable',
              templateUrl: encodeURL('/resources/views/table/footable.html')
          }) 
          .state('app.table.nggrid', {
              url: '/nggrid',
              templateUrl: encodeURL('/resources/views/table/nggrid.html'),
              resolve: {
                  deps: function( $ocLazyLoad ){
                	  return $ocLazyLoad.load('ngGrid').then(
                            function(){
                            	 return $ocLazyLoad.load(encodeURL('/resources/js/controller/table/gridcontroller.js'));
                            }
                      );                      
                  }
              }
          }) 
          
          /****************************** FORM 模块开始 ******************************/
          .state('app.form', {
              url: '/form',
              template: '<div ui-view class="fd-enter"></div>',
              resolve: {
                  deps: function(uiLoad){
                      return uiLoad.load(encodeURL('/resources/js/controller/form/formcontroller.js'));
                  }
              }
          })
          .state('app.form.elements', {
              url: '/elements',
              templateUrl: encodeURL('/resources/views/form/elements.html'),
              resolve: {
                  deps: function(uiLoad){
                      return uiLoad.load(encodeURL('/resources/js/controller/uikits/bootstrapcontroller.js'));
                  }
              }
          })
          .state('app.form.validation', {
              url: '/validation',
              templateUrl: encodeURL('/resources/views/form/validation.html')
          })
          .state('app.form.wizard', {
              url: '/wizard',
              templateUrl: encodeURL('/resources/views/form/wizard.html')
          })
          .state('app.form.fileupload', {
              url: '/fileupload',
              templateUrl: encodeURL('/resources/views/form/fileupload.html'),
              resolve: {
                  deps: function( $ocLazyLoad){
                      return $ocLazyLoad.load('angularFileUpload').then(
                           function(){
                          		return $ocLazyLoad.load(encodeURL('/resources/js/controller/form/uploadcontroller.js'));
                           }
                      );
                  }
              }
          })
          .state('app.form.imagecrop', {
              url: '/imagecrop',
              templateUrl: encodeURL('/resources/views/form/imagecrop.html'),
              resolve: {
                  deps: function( $ocLazyLoad){
                      return $ocLazyLoad.load('ngImgCrop').then(
                          function(){
                              return $ocLazyLoad.load(encodeURL('/resources/js/controller/form/imgcorpcontroller.js'));
                          }
                      );
                  }
              }
          })
          .state('app.form.select', {
              url: '/select',
              templateUrl: encodeURL('/resources/views/form/select.html'),
              controller: 'SelectCtrl',
              resolve: {
                  deps: function( $ocLazyLoad ){
                      return $ocLazyLoad.load('ui.select').then(
                          function(){
                              return $ocLazyLoad.load(encodeURL('/resources/js/controller/form/selectcontroller.js'));
                          }
                      );
                  }
              }
          })
          .state('app.form.slider', {
              url: '/slider',
              templateUrl: encodeURL('/resources/views/form/slider.html'),
              controller: 'SliderCtrl',
              resolve: {
                  deps: function( $ocLazyLoad ){
                      return $ocLazyLoad.load('vr.directives.slider').then(
                          function(){
                              return $ocLazyLoad.load(encodeURL('/resources/js/controller/form/slidercontroller.js'));
                          }
                      );
                  }
              }
          })
          .state('app.form.editor', {
              url: '/editor',
              templateUrl: encodeURL('/resources/views/form/editor.html'),
              controller: 'EditorCtrl',
              resolve: {
                  deps: ['$ocLazyLoad',
                    function( $ocLazyLoad ){
                      return $ocLazyLoad.load('textAngular').then(
                          function(){
                              return $ocLazyLoad.load(encodeURL('/resources/js/controller/form/editorcontroller.js'));
                          }
                      );
                  }]
              }
          }) 
          
          /****************************** TREE 模块开始 ******************************/
          .state('app.tree', {
              url: '/tree',
              template: '<div ui-view class="fd-enter"></div>'
          })
          .state('app.tree.navtree', {
              url: '/navtree',
              templateUrl: encodeURL('/resources/views/tree/navtree.html'),
              resolve: {
                  deps: function( $ocLazyLoad ){
                	  return $ocLazyLoad.load('angularBootstrapNavTree').then(
                          function(){
                             return $ocLazyLoad.load(encodeURL('/resources/js/controller/tree/navtreecontroller.js'));
                          }
                      );                    
                  }
              }     
          }) 
          
          /****************************** CHART 模块开始 ******************************/
          .state('app.chart', {
              url: '/chart',
              templateUrl: encodeURL('/resources/views/chart/chart.html'),
              resolve: {
                  deps: function( $ocLazyLoad ){
                	  return $ocLazyLoad.load(encodeURL('/resources/js/controller/chart/chartcontroller.js'));                   
                  }
              }     
          }) 
          
          /****************************** Calendar 模块开始 ******************************/
          .state('app.calendar', {
              url: '/calendar',
              templateUrl: encodeURL('/resources/views/calendar/calendar.html'),
              resolve: {
            	  deps: function( $ocLazyLoad, uiLoad ){
            		  return uiLoad.load([encodeURL('/resources/vendor/jquery/fullcalendar/fullcalendar.css'),
            		                      encodeURL('/resources/vendor/jquery/fullcalendar/theme.css'),
    		  		                      encodeURL('/resources/vendor/jquery/jquery-ui-1.10.3.custom.min.js'),
    		  		                      encodeURL('/resources/vendor/libs/moment.min.js'),
    		  		                	  encodeURL('/resources/vendor/jquery/fullcalendar/fullcalendar.min.js'),
    		  		                	  encodeURL('/resources/js/controller/calendar/calendarcontroller.js')]
                       ).then(function(){
                    	   return $ocLazyLoad.load('ui.calendar'); //用于将jquery的fullcalendar集成到angularjs中   
                       })
                  }
              }     
          }) 
  });